#include <at89c51RC2.h>
#include <OneWire.h>

#define DS18B02_SKIP_ROM   0xCC
#define DS18B02_CONVERT_T   0x44
#define DS18B02_READ_SCRATCHPAD   0xBE

/**
  * @brief 温度变换
  * @param 无
  * @retval 无
  */
void DS18B20_ConvertT(void)
{
	OneWire_Init();
	OneWire_SendByte(DS18B02_SKIP_ROM);
	OneWire_SendByte(DS18B02_CONVERT_T);
}

/**
  * @brief 温度读取
  * @param 无
  * @retval T 当前温度
  */
float DS18B20_ReadT(void)
{
	unsigned char TLSB,TMSB;
	int Temp;
	float T;
	
	OneWire_Init();
	OneWire_SendByte(DS18B02_SKIP_ROM);
	OneWire_SendByte(DS18B02_READ_SCRATCHPAD);
	TLSB=OneWire_ReceiveByte();
	TMSB=OneWire_ReceiveByte();
	Temp=(TMSB<<8)|TLSB;
	T=Temp/16.0;
	
	return T;
}